#include "Variable.h"
#include "Pattern.h"

namespace TreeExpression {

Variable::Variable(std::string _name) :  Expression_CRTP<Variable>(), name(_name) { }

Variable::Variable(const Variable& copy) : Expression(copy), Expression_CRTP<Variable>(copy), name(copy.name) { }

Variable::~Variable() { }

AutoPointer<Expression> Variable::eval(CopyPointer<Context>& context) {
	AutoPointer<Expression> variable = context->searchValueDefinitionInGlobal(name);
	if (variable.isNull()) {
		return AutoPointer<Expression>(new Variable(*this));
	}
	else {
		return variable;//TODO copy pointer
	}
}

std::string Variable::getHash() const {
	return "Variable";
}

std::string Variable::toString() const {
	return name;
}

std::string Variable::getName() const {
	return name;
}

}

